﻿using Postal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Titul.Help.WebUI.Controllers
{
    public partial class SupportController : Controller
    {
        [HttpGet]
        [AllowAnonymous]
        public virtual ActionResult Edit()
        {
            var question = new Models.Question();
            return View(question);
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public virtual ActionResult Edit(Models.Question question)
        {
            if (ModelState.IsValid)
            {
                var senderEmail = "simlex.dev.2014@gmail.com";

                dynamic email = new Email(MVC.Emails.Views.Question);
                email.Text = question.Text;
                email.To = senderEmail;
                email.From = question.Email;
                email.Send();

                return RedirectToAction(MVC.Support.SuccessSendQuestion());
            }
            else
                return View(question);
        }

        [HttpGet]
        [AllowAnonymous]
        public virtual ViewResult SuccessSendQuestion()
        {
            return View();
        }
    }
}